﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Otonomos.World;
using Otonomos.Utils.Serialization;
using Test.Otonomos.Utils;

namespace Test.Otonomos.World
{
    [TestClass]
    public class TestWorld2D : TestClassWithContainer
    {
        [TestMethod]
        public void WorldSerializationDeserialization()
        {
            var parts = new List<Object2D>();
            parts.Add(new SimpleWall2D(new Point2D(0, 0), new Point2D(1, 0), WallType.SingleLeft));
            parts.Add(new SimpleWall2D(new Point2D(1, 0), new Point2D(1, 1), WallType.SingleLeft));
            parts.Add(new SimpleWall2D(new Point2D(1, 1), new Point2D(0, 1), WallType.SingleLeft));
            parts.Add(new SimpleWall2D(new Point2D(0, 1), new Point2D(0, 0), WallType.SingleLeft));
            parts.Add(new SimpleWall2D(new Point2D(.25, .25), new Point2D(.75, .75), WallType.DoubleSided));

            World2D myWorld = new World2D(parts);
            var serializer = Resolve<ISerializer>();

            string fileName = string.Format("{0}.{1}", Guid.NewGuid(), serializer.DefaultExtension);
            serializer.Serialize(myWorld, fileName);

            var otherWorld = serializer.Deserialize<World2D>(fileName);
            File.Delete(fileName);
            Assert.AreEqual(otherWorld.Count, myWorld.Count);
            Assert.AreEqual(otherWorld[0], myWorld[0]);
            CollectionAssert.AreEqual(otherWorld, myWorld);
        }
    }
}
